package com.rjj.wlqq.index;

import com.rjj.wlqq.tool.io.FileKit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;

/**
 * @author renjianjun
 * @date 2020/8/13 11:03
 * @email 215060580@qq.com
 * 首页
 */
@Slf4j
@Controller
public class IndexController {

    @RequestMapping({"", "/", "/index", "index"})
    public String index() {
        return "index";
    }


    /**
     * 文件下载工具测试
     */
    @RequestMapping("/download/test")
    public void download(HttpServletRequest request, HttpServletResponse response) {
        String fineName = "/Users/renjianjun/study/ideaWorkSpace/wlqq/src/main/resources/static/img/mao.jpg";
        try {
            //Download.download(fileName,request,response);
            FileKit.downloadResponse(fineName, request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/pathTest")
    @ResponseBody
    public void pathTest(HttpServletRequest request, String a) throws FileNotFoundException {
        String servletPath = request.getServletPath();
        log.info("servletPath:{}", servletPath);
        String contextPath = request.getServletContext().getContextPath();
        log.info("contextPath:{}", contextPath);
        log.info("a" + a);

        /*String logLocality = ConsoleUtil.getDebugInfo();
        log.info(logLocality);*/
    }
}
